package com.ssm.sfzy.controller;
import com.ssm.sfzy.constant.CommonConstant;
import com.ssm.sfzy.entity.ArticleType;
import com.ssm.sfzy.service.ArticleTypeService;
import com.ssm.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
 * @Author yang "每天都要学习呀"
 * @Date 2024 03 30 11 32
 **/

@RestController
@CrossOrigin
@RequestMapping("/articleType")
public class ArticleTypeController {
    @Autowired
    private ArticleTypeService articleTypeService;

    @GetMapping("/find")
    public Object find(
            @RequestParam(defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            ArticleType articleType
    ){
        Map<String, Object> map = articleTypeService.findPage(pageNum, pageSize, articleType);
        return  Result.success(map);
    }


    @GetMapping("/findById/{id}")
    public Object findById(@PathVariable Integer id){
        ArticleType articleType = articleTypeService.findById(id);
        System.out.println(articleType);
        return Result.success(articleType);
    }


    @PostMapping("/add")
    public Object add(@RequestBody ArticleType articleType) throws Exception {
        articleTypeService.add(articleType);
        return Result.success(articleType);
    }

    @PostMapping("/edit")
    public Object edit(@RequestBody ArticleType articleType) throws Exception {
        articleTypeService.edit(articleType);
        return Result.success(articleType);
    }
    @DeleteMapping("/remove/{id}")
    public Object remove(@PathVariable Integer id){
        articleTypeService.remove(id);
        return Result.success(id);
    }

    @DeleteMapping("/removeBatch")
    public Object removeBatch(Integer[] ids){
        articleTypeService.removeBatch(ids);
        return Result.success(ids);
    }
}
